﻿<?php
session_start();
include("../public_files/conn.php");
if(isset($_SESSION['status'])){
$user_id=$_SESSION['userid'];}else{
$user_id=0;
}
$list_name_id=$_POST['list_name_id'];		//榜单id
$ranking=$_POST['ranking'];					//排名
$offic_or_user=$_POST['offic_or_user'];		//官方还是用户
if($offic_or_user==0){
	$date_tabel="official_vote_ip";
	$tabel_content="official_list_content";
	$list_name="official_list_name";
}else{
$date_tabel="user_vote_ip";
$tabel_content="user_list_content";
$list_name="user_list_name";
}
$result=mysql_query("select * from ".$date_tabel." where list_id='$list_name_id' and ranking='$ranking'")or die(mysql_error());
if($row=mysql_fetch_array($result)){
 
echo "er";
}else{
$vote_id=$_POST['vote_id'];			//投票栏一项id
$result=mysql_query("select * from ".$tabel_content." where id='$vote_id'");
$row=mysql_fetch_array($result);
$vote=$row['content'];
$vote+=1;
$sql="update ".$tabel_content." set content='$vote' where id='$vote_id'";
$result=mysql_query($sql);
		echo  $vote;

$result=mysql_query("select * from ".$list_name." where id='$list_name_id'");
$row=mysql_fetch_array($result);
$vote_total=$row['vote_total'];
$vote_total+=1;
$sql="update ".$list_name." set vote_total='$vote_total' where id='$list_name_id'";
$result=mysql_query($sql);		
		
		
		$vote_ip=ip();
		$sql3="insert into ".$date_tabel." (list_id,ranking,vote_ip,user_id) values ('$list_name_id','$ranking','$vote_ip',$user_id)";
		$result=mysql_query($sql3)or die(mysql_error());

	$sql="select * from already_vote where list_id='$list_name_id'  and  user_id='$user_id' and offi_or_user='$offic_or_user'";
	$result=mysql_query($sql);
	
	if($rows=mysql_fetch_array($result)){
	}else{
	$sql3="insert into already_vote (list_id,user_id,offi_or_user) values ('$list_name_id',$user_id,$offic_or_user)";
	$result=mysql_query($sql3)or die(mysql_error());
	
	}
		
		
		
		
		
}

?>
<?php
		///////////////提取客户端IP///////////////////////////////////////////////////////////////////////////////////////////
		function iptype1 () { 
			if (getenv("HTTP_CLIENT_IP")) { 
			   return getenv("HTTP_CLIENT_IP"); 
			} 
			else { 
			   return "none"; 
			} 
		} 
		function iptype2 () { 
			if (getenv("HTTP_X_FORWARDED_FOR")) { 		///跳过代理服务器取得用户真实IP
			   return getenv("HTTP_X_FORWARDED_FOR"); 
			} 
			else { 
			   return "none"; 
			} 
		} 
		function iptype3 () { 
			if (getenv("REMOTE_ADDR")) { 
			   return getenv("REMOTE_ADDR"); 	///获取用户端IP或者代理服务器真实IP
			} 
			else { 
			   return "none"; 
			} 
		} 
		function ip() { 
			$ip1 = iptype1(); 
			  $ip2 = iptype2(); 
			$ip3 = iptype3(); 
			if (isset($ip1) && $ip1 != "none" && $ip1 != "unknown") { 
			   return $ip1; 
			} 
			elseif (isset($ip2) && $ip2 != "none" && $ip2 != "unknown") { 
			   return $ip2; 
			} 
			elseif (isset($ip3) && $ip3 != "none" && $ip3 != "unknown") { 
			   return $ip3; 
			}   
			  else { 
			  return "none"; 
			} 
		}

		?>